<!DOCTYPE html>
<html lang="en">

    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>Document</title>
    </head>

    <body>
        <script>
            // var promise1 = Promise.reject(3);
            // var promise2 = 42;
            // var promise3 = new Promise(function (resolve, reject) {
            //     setTimeout(resolve, 100, 'foo');
            // });

            // Promise.all([promise1, promise2, promise3]).then(function (values) {
            //     console.log('aa', values), function (val) {
            //         console.log('err', val);

            //     };
            // });
            // expected output: Array [3, 42, "foo"]

            let wake = (time) => {
                return new Promise((resolve, reject) => {
                    setTimeout(() => {
                        resolve(`${time / 1000}秒后醒来`)
                    }, time)
                })
            }

            let wake2 = (time) => {
                return new Promise((resolve, reject) => {
                    setTimeout(() => {
                        reject(`${time / 1000}---秒后醒来`)
                    }, time)
                })
            }

            // let p1 = wake(3000)
            // let p2 = wake(100)
            // let p3 = wake(5500)

            // Promise.all([p1, p2, p3]).then((result) => {
            //     console.log(result)       // [ '3秒后醒来', '2秒后醒来' ]
            // }).catch((error) => {
            //     console.log('err', error)  // catch可以收到抛出的错误,
            // })
            wake(3000).then((a) => {
                console.log('a', a);
                return wake2(100);
            }).then((b) => {
                console.log('b', b);
                return wake(5500)
            }).then((c) => {
                console.log('c', c);
            })
        </script>
    </body>

</html>